# agents/factor_agents/mydei_agent.py
from .base_factor_agent import BaseFactorAgent
from game_engine.game_state import FactorDevelopment, GameWorld
import numpy as np

class MydeiAgent(BaseFactorAgent):
    """万敌智能体 - 烧血反击特化"""
    
    def __init__(self, factor: FactorDevelopment, game_world: GameWorld):
        super().__init__(factor, game_world)
        self.personality_traits.update({
            "aggression": 0.8,      # 高攻击性
            "caution": 0.3,         # 低谨慎性
            "blood_rage_threshold": 0.4  # 血怒阈值
        })
    
    def make_decision(self, current_time: int) -> str:
        """万敌的决策逻辑"""
        situation = self.evaluate_situation()
        
        # 血量低于阈值时进入血怒状态
        if self.factor.attributes['health'] < self.factor.attributes['health'] * self.personality_traits["blood_rage_threshold"]:
            return self._blood_rage_decision(situation)
        
        # 正常状态决策
        if situation["nearby_threats"]:
            if self.factor.attributes['health'] > self.factor.attributes['health'] * 0.7:
                return "engage_combat"
            else:
                return "tactical_retreat"
        elif situation["nearby_allies_need_help"]:
            return "support_allies"
        else:
            return "train_combat"
    
    def evaluate_situation(self) -> Dict:
        """评估当前局势"""
        nearby_factors = self.get_nearby_factors()
        threats = [f for f in nearby_factors if self._is_potential_threat(f)]
        allies_need_help = [f for f in nearby_factors if f.attributes['health'] < f.attributes['health'] * 0.4]
        
        return {
            "nearby_threats": threats,
            "nearby_allies_need_help": allies_need_help,
            "health_ratio": self.factor.attributes['health'] / 100.0,
            "special_charges": self.factor.special_charges
        }
    
    def _blood_rage_decision(self, situation: Dict) -> str:
        """血怒状态决策"""
        if situation["nearby_threats"]:
            if self.should_use_special_ability():
                return "burn_blood_counter"
            else:
                return "frenzy_attack"
        else:
            return "seek_vengeance"